package com.ghf.dp1;

import java.io.InputStream;
import java.util.Scanner;

//封装,
//单纯将计算封装为方法,程序不易扩展,增加一种计算方式只能方法
public class Operation {

    //封装计算操作
    public static double result(double numa, double numb, String operate) {
        double result = 0d;
        switch (operate) {
            case "+":
                result = numa + numb;
                break;
            case "-":
                result = numa - numb;
                break;
            case "*":
                result = numa * numb;
                break;
            case "/":
                result = numa / numb;
                break;
        }
        return result;
    }


    public static void main(String[] args) throws Exception {
        try {
            System.out.println("请输入数字A：");
            byte[] bytes = new byte[1024];
            int i = 0;
            InputStream in = System.in;
//            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//            if ((i = in.read(bytes)) != -1) {
//                byteArrayOutputStream.write(bytes, 0, i);
//            }
//            String numa = new String(byteArrayOutputStream.toByteArray());

            String numa = "",opt = "",numb = "";
            Scanner scanner = new Scanner(in,"UTF-8");

            if(scanner.hasNext()){
                numa = scanner.next();
            }
            System.out.println("请选择运算符号（+、-、*、/）：");
            if(scanner.hasNext()){
                opt = scanner.next();
            }
            System.out.println("请输入数字B：");
            if(scanner.hasNext()){
                numb = scanner.next();
            }

            double result = Operation.result(Double.valueOf(numa), Double.valueOf(numb), opt);
            System.out.println("结果是：" + result);

//            string strNumberA = Console.class.get.ReadLine（）;
//            Console.Write（"请选择运算符号（+、-、*、/）："）;
//            string strOperate = Console.ReadLine（）;
//            Console.Write（"请输入数字B："）;
//            string strNumberB = Console.ReadLine（）;
//            string strResult = "";
//            strResult = Convert.ToString（Operation.GetResult（Convert.ToDouble（strNumberA），
//            Convert.ToDouble（strNumberB），strOperate））;
//            Console.WriteLine（"结果是：" + strResult）;
//            Console.ReadLine（）;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
